<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <input type="text" v-model="msg">
    {{msg}}
    <hr>
    <button @click="addLi">新增li</button>
    {{arr}}
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp({
      data(){
        return {
          msg: '你好vue',
          arr: [1,2,3,4]
        }
      },
      methods: {
        addLi() {
          this.arr.push(this.arr.length+1);
        }
      },
      // 侦听基础数据类型
      watch: {
        msg(newVal, oldVal){
          console.log('msg改变了值是', newVal);
        },
        /* arr(newVal){
          console.log('arr改变了值是', newVal);
        } */
        // 侦听引用类型 数组或者对象
        arr: {
          handler(newVal){
            console.log('arr改变了值是', newVal);
          },
          deep: true // 深度监听的
        }

      }
    })
    app.mount('#app')
  </script>
</body>
</html>